package com.wpp.lagouservicecode.controller;

import com.wpp.core.email.SendEmailParam;
import com.wpp.core.result.ResultDTO;
import com.wpp.lagouservicecode.feign.SendEmailFeignClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author wpp25
 * @date 2021/5/16 19:19
 * @description：
 */
@RestController
@RequestMapping("/api/code")
public class CodeController {

    @Value("${eureka.instance.metadata-map.code}")
    private String code;

    @Resource
    private SendEmailFeignClient sendEmailFeignClient;

    @GetMapping("/create")
    public ResultDTO<String> create(@RequestParam("email") String email){
        SendEmailParam sendEmailParam = new SendEmailParam();
        sendEmailParam.setContent(code);
        sendEmailParam.setSubject("codeEmail");
        sendEmailParam.setReceiveEmail(email);
        sendEmailFeignClient.sendSimpleMail(sendEmailParam);
        return ResultDTO.successResult(code);
    }

    @GetMapping()
    public ResultDTO<String> getCode(){

        return ResultDTO.successResult(code);
    }

}
